#
#
# Makefile (for the JTRunAlertPanel library)
# Created by Joel Lawrence Tucci on 09-March-2011.
# 
# Copyright (c) 2011 Joel Lawrence Tucci
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# Neither the name of the project's author nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#


CC=gcc-4.2

#TODO: figure this out automatically
IOS_VERSION=4.3
IOS_SIM_SDK_LOC=SDKs/iPhoneSimulator$(IOS_VERSION).sdk/
IOS_DEV_SDK_LOC=SDKs/iPhoneOS$(IOS_VERSION).sdk/

#Place to put the various compiled libraries, we need to keep the sim and device libraries in separate directories
IOS_DEV_DIR=ios_dev_libs/
IOS_SIM_DIR=ios_sim_libs/

#Need the various ios dev and sim directories
IOS_PLAT_PREFIX=/Developer/Platforms/
IOS_DEV_PLAT=$(IOS_PLAT_PREFIX)iPhoneOS.platform/Developer/
IOS_SIM_PLAT=$(IOS_PLAT_PREFIX)iPhoneSimulator.platform/Developer/

#The directories relative structure is the same(at least for the time being)
IOS_CC_SUFFIX=usr/bin/gcc-4.2
IOS_LIBTOOL_SUFFIX=usr/bin/libtool

IOS_SIM_ARCH=i386
IOS_DEV_ARCH=armv6 armv7

IOS_SIM_ARCH_FLAG=-arch $(IOS_SIM_ARCH)
IOS_DEV_ARCH_FLAG=-arch armv6 -arch armv7

IOS_DEV_LIBTOOL_CMD=$(IOS_DEV_PLAT)$(IOS_LIBTOOL_SUFFIX)
IOS_SIM_LIBTOOL_CMD=$(IOS_SIM_PLAT)$(IOS_LIBTOOL_SUFFIX)


#Necessary for newer versions of llvm
OS_X_VER=10.6
OS_X_SDK_DIR=/Developer/SDKs/MacOSX$(OS_X_VER).sdk/

CFLAGS=-Wall -x objective-c -fmessage-length=0 -pipe -std=gnu99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -DDEBUG -I ./include -fexceptions -gdwarf-2 -fobjc-abi-version=2 -fobjc-legacy-dispatch -D__IPHONE_OS_VERSION_MIN_REQUIRED=40200 -c


IOS_LIB_NAME=JTRunAlertPanelController.o
LDFLAGS=-framework Foundation

SOURCE_FILE_LIST=JTRunAlertPanel_Prefix.pch JTRunAlertPanelController.m

LIB_FILE_NAME=libJTRunAlertPanel.a

all: iossim iosdev

iossim: 
	mkdir -p $(IOS_SIM_DIR)
	$(IOS_SIM_PLAT)$(IOS_CC_SUFFIX) $(CFLAGS) $(IOS_SIM_ARCH_FLAG) -isysroot $(IOS_SIM_PLAT)$(IOS_SIM_SDK_LOC) $(SOURCE_FILE_LIST) 
	$(IOS_SIM_LIBTOOL_CMD) -arch_only $(IOS_SIM_ARCH) $(LDFLAGS) -L $(IOS_LIB_NAME) -o $(IOS_SIM_DIR)$(IOS_LIB_NAME)
	$(IOS_SIM_LIBTOOL_CMD) -arch_only $(IOS_SIM_ARCH) $(LDFLAGS_APPLE) -L $(IOS_LIB_NAME) -o $(IOS_SIM_DIR)$(LIB_FILE_NAME)


iosdev: 
	mkdir -p $(IOS_DEV_DIR)	
	$(IOS_DEV_PLAT)$(IOS_CC_SUFFIX) $(CFLAGS) $(IOS_DEV_ARCH_FLAG) -isysroot $(IOS_DEV_PLAT)$(IOS_DEV_SDK_LOC) $(SOURCE_FILE_LIST)
	for architecture in $(IOS_DEV_ARCH) ; do \
	 $(IOS_DEV_LIBTOOL_CMD) -arch_only $$architecture $(LDFLAGS) -L $(IOS_LIB_NAME) -o $(IOS_DEV_DIR)libJTRunAlertPanel_$$architecture.a ; \
	done
#Now join the archs together in a single library.
	$(IOS_DEV_LIBTOOL_CMD) -static $(foreach architecture,$(IOS_DEV_ARCH),$(IOS_DEV_DIR)libJTRunAlertPanel_$(architecture).a) -o $(IOS_DEV_DIR)$(LIB_FILE_NAME)

clean:
	rm -f *.o
	rm -f *.a
	rm -f *.lo
	rm -f *.lai
	rm -rf .libs
	rm -rf $(IOS_SIM_DIR)
	rm -rf $(IOS_DEV_DIR)
	rm -f $(STANDALONE_EXECUTABLE_NAME)

